<template>
  <div id="app">
    <el-container>
      <el-header>
        <nav class="navbar">
          <div class="navbar-brand">
            <h2>用户登录系统</h2>
          </div>
          <div class="navbar-nav" v-if="currentUser">
            <span>欢迎, {{ currentUser.username }}!</span>
            <el-button @click="logout" type="danger" size="small" style="margin-left: 10px;">
              退出登录
            </el-button>
          </div>
        </nav>
      </el-header>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'App',
  computed: {
    currentUser () {
      return this.$store ? this.$store.state.auth.user : JSON.parse(localStorage.getItem('user'))
    }
  },
  methods: {
    logout () {
      localStorage.removeItem('user')
      localStorage.removeItem('token')
      this.$router.push('/login')
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  background-color: #409eff;
  color: white;
}

.navbar-brand h2 {
  margin: 0;
  color: white;
}

.navbar-nav {
  display: flex;
  align-items: center;
  color: white;
}

.el-header {
  padding: 0;
  background-color: #409eff;
}

.el-main {
  padding: 20px;
}
</style>
